package ShareYourWay.webpages;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;

import ShareYourWay.functions.App;
import ShareYourWay.functions.Functions_Meetup;
import ShareYourWay.functions.SignInSession;
import ShareYourWay.project.Meetup;
import ShareYourWay.project.User;

public class PanelMeetsOn extends Panel {
private static final long serialVersionUID = 1L;
	
	SignInSession s = SignInSession.get();
	User user = s.getUser();

	Label l1 = null;
	
	private List<Meetup> listameets;
	final App app;
	ListView ListMeetView;
	
	@SuppressWarnings("unchecked")
	
	public PanelMeetsOn(String id) {	
	
		super(id);	
		
		System.out.println("Dentro de panelyourmeets");
		
		app = new App();
		this.listameets = new LinkedList<Meetup>();
		load();
		
		final Functions_Meetup meets = new Functions_Meetup();
		
		final ArrayList<Integer> nomeet = meets.getnoshow();
		
		this.setOutputMarkupId(true);

		this.ListMeetView =new ListView("meets_list",this.listameets){
				
				private static final long serialVersionUID = 1L;
		            @Override
		            protected void populateItem(final ListItem item) {           	
		  			           	
		                final Meetup meet = (Meetup) item.getModelObject(); 
		                
		            
		                
		                item.setIndex(meet.getIdMeetup());               
		                
		                
		                
//		                if(meet.getIdMeet()==4) {
//		                	
//		                	item.setOutputMarkupId(true);
//		                	item.setVisible(false);   	
//		                	
//		                	
//		                	
//		                }
													
		                    
		                  final PropertyModel<Integer> messageModel = new PropertyModel<Integer>(meet, "idMeetup");
//		                    l1=new Label("id", messageModel);	
//		                    item.add(l1);
			                item.add(new Label("vehiculo", meet.getVehicle()));
			                item.add(new Label("destino",  meet.getDestination()));//meet.getOcity()));
			                item.add(new Label("origen",  meet.getOrigin()));//meet.getDcity()));  
			                item.add(new Label("slots",meet.getSlots()));			                
			                
//			                item.add(new AjaxLink("noshow") {		                	
//			     
//			                	/**
//								 * 
//								 */
//								private static final long serialVersionUID = 1L;
//
//								public void onClick( AjaxRequestTarget target ){ 	
////									int idmeet =meet.getIdMeetup();
////									
////									System.out.println("///////@@@@@@@@@@" + user.getId());
////									
////									app.hideUserMeetup(idmeet, user.getId());
////									
////									target.add(PanelMeets.this);
//									app.updateslot(meet.getIdMeetup());							
//									
//									//target.add(Meets.class);
//									int idmeet =meet.getIdMeetup();
//									System.out.println(meet.getIdMeetup());
//									//target.appendJavaScript("salir();");
//									app.hideUserMeetup(idmeet,user);
//									PanelMeetsOn.this.load();
//								
//									target.add(PanelMeetsOn.this);
////			                		
//		              			   } 			                	
//			                	
//			                	
//			                });
//			                
//			                item.add(new AjaxLink("meetup") {		                	
//			   			     
//			                	/**
//								 * 
//								 */
//								private static final long serialVersionUID = 1L;
//
//								public void onClick( AjaxRequestTarget target ){ 
//			                		
//			                								
//									
//									app.updateslot(meet.getIdMeetup());							
//	
//									//target.add(Meets.class);
//									int idmeet =meet.getIdMeetup();
//						
//									System.out.println(meet.getIdMeetup());
//									//target.appendJavaScript("salir();");
//									app.insertusermeetup(idmeet,user);
//									PanelMeetsOn.this.load();
//								
//									target.add(PanelMeetsOn.this);
//			                		
//		              			   }                 	
//			                	
//			                	
//			                });			  
//			                
//			                item.add(new AjaxLink("mostrar") {
//
//								@Override
//								public void onClick(AjaxRequestTarget arg0) {
//									// TODO Auto-generated method stub
//									
//								}});
		            	           
					
		               
		            } // fin populate
		        };
		
		
		
		        add(ListMeetView); 

	} // Fin constructor
	
	public void load(){
		
		this.listameets.clear();
		for (Meetup m: app.ListMeetupOn(user)){
			this.listameets.add(m);
		}
	}
	
    public void onConfigure() {
    	
	    super.onConfigure();

	}
    
    
    public void listar () {
 
    }
}
